<script language="javascript" src="./include/js/validate.js"></script>
<script language="javascript" src="include/js/jquery.js?v=1.3.2"></script>
<script type="text/javascript">
function textareasize(obj)
{
	if(obj.scrollHeight > 70) {
		obj.style.height = obj.scrollHeight + 'px';
	}
}

function insertText(text)
{
	$("#template").focus();
    var str = document.selection.createRange();
	str.text = text;
}

function openwinx(url,name,w,h)
{
    window.open(url,name,"top=100,left=400,width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
</script>
	<div id="nav">
		当前位置: <a href="?action=default">管理首页</a> <span>&gt;</span> <a href="?action=block">碎片管理</a> <span>&gt;</span> 修改碎片 [<font color="#FF0000"><?=$blockname?></font>]
	</div>
	<form id="theform" name="theform" action="" method="post" class="block" enctype="multipart/form-data" onSubmit="return Validator.Validate(this,2);">
	<table summary="" cellpadding="0" cellspacing="0" border="0" width="100%">
	<? if ($isarray){
			if(!isset($rows)) $rows = 8;
	?>
	<script type="text/javascript">
		$('#sidebar').hide();
	</script>
		<tr> 
  			<th width="10" id="th_id">ID</th>
  			<th width="200" id="th_title">标题</th>
  			<th width="180" id="th_url">链接</th>
			<th width="150" id="th_thumb">缩略图</th>
			<th width="60" id="th_date">日期</th>
			<th width="230" id="th_description">摘要</th>
		</tr>
		<?php 
			for($i = 0; $i < $rows; $i++){	
		?>
		<tr>
			<td width="10"><?=($i+1)?></td>
			<td width="*"><input type="text" name="data[<?=$i?>][title]" id="title_<?=$i?>" value="<?=htmlspecialchars(stripslashes($data[$i]['title']))?>" style="width:100%"></td>
			<td width="200" class="align_c"><input type="text" name="data[<?=$i?>][url]" id="url_<?=$i?>" value="<?=$data[$i]['url']?>" size="30"></td>
			<td width="150"><input type="text" name="data[<?=$i?>][thumb]" id="thumb_<?=$i?>" size="15" value="<?=$data[$i]['thumb']?>"> <input name="thumb_<?=$i?>_aid" id="thumb_<?=$i?>_aid" type="hidden"><input type="button" name="thumb_upimage" value="上传" style="width:40px" onClick="javascript:openwinx('?action=upload&inputid=thumb_<?=$i?>&filepath=<?=$filepath?>','upload','450','350')"/></td>
			<td width="70"><input type="text" name="data[<?=$i?>][date]" id="date_<?=$i?>" value="<?=$data[$i]['date']?>" size="10"></td>
			<td width="200"><textarea name="data[<?=$i?>][description]" id="description_<?=$i?>" style="width:100%;height:45px;"><?=$data[$i]['description']?></textarea></td>
		</tr>
		<?php } ?>
		<tr>
			<td colspan="6">模板代码</td>
		</tr>
		<tr>
			<td colspan="4"><textarea name="template" id="template" style="width:96%;height:120px; font:14px sans-serif;" onkeyup="textareasize(this);"><?php if($template){ echo $template; }else{ ?><h4>{$blockname}</h4>
<ul>
{loop $data $n $r}
   <li><a href="{$r[url]}">{cutstr($r[title], 40)} {$r[date]}</a></li>
{/loop}
</ul>
<?php } ?></textarea></td>
			<td colspan="2" style="text-align:center;"><div style="height:25px;" id="template_example"></div>
			<span style="height:25px"><input type="button" value="循环开始" title="点击插入" style="width:60px" onClick="javascript:insertText('{loop $data $n $r}')" /></span>
	<span style="height:25px"><input type="button" value="循环结束" title="点击插入" style="width:60px" onClick="javascript:insertText('{/loop}')" /></span><br />
	<span style="height:25px"><input type="button" value="碎片名称" title="点击插入" style="width:60px" onClick="javascript:insertText('{$blockname}')" /></span>
	<span style="height:25px"><input type="button" value="标题" title="点击插入" style="width:60px" onClick="javascript:insertText('{$r[title]}')" /></span><br />
	<span style="height:25px"><input type="button" value="链接" title="点击插入" style="width:60px" onClick="javascript:insertText('{$r[url]}')" /></span>
	<span style="height:25px"><input type="button" value="缩略图" title="点击插入" style="width:60px" onClick="javascript:insertText('{$r[thumb]}')" /></span><br />
	<span style="height:25px"><input type="button" value="日期" title="点击插入" style="width:60px" onClick="javascript:insertText('{$r[date]}')" /></span>
	<span style="height:25px"><input type="button" value="简介" title="点击插入" style="width:60px" onClick="javascript:insertText('{$r[description]}')" /></span>
			</td>
		</tr>
	<? } else {?>
		<tr>
		<th>碎片代码 </th>
		<td><textarea id="data" name="data" rows="12" cols="80" style="font:14px sans-serif;" onkeyup="textareasize(this);"><?=$data?></textarea></td>
		</tr>
	<? }?>
		<tr>
		<td colspan="6">
		<button value="true" type="submit" name="dosubmit" class="submit">保存</button></td>
		</tr>
	</table>
	</form>
<script type="text/javascript">
$(document).ready(function(){
		$('#template_example').load("admincp.php",{"action" : "block","op":"get_template_example"});
});
</script>